<?php
/**
 * @file WCSession.php
 * @author Alejandro Dario Simi
 * @date $Date: 2013-05-13 04:08:49 +0000 (Mon, 13 May 2013) $
 *
 * $Id: WCSession.php 64 2013-05-13 04:08:49Z daemonraco@gmail.com $
 * $URL: http://wcomix.googlecode.com/svn/tags/wcomix-1.0-BETA1/includes/security/WCSession.php $
 */

/**
 * @class WCSession
 */
class WCSession extends WCTableRepresentation {
	protected	$_PropertiesReadOnly	= array("id");
	protected	$_PropertiesPrefix	= "sess_";
	protected	$_PropertiesTable	= "sessions";
	protected	$_PropertiesAutoSet	= ", sess_timestamp = sysdate()";
	
	//
	// Public methods
	public function load($id) {
		parent::load($id);

		if($this->ok() && !$this->salt) {
			$this->salt = rand(1, 999999);
		}
		
		return $this->ok();
	}
	public function setId($id) {
		$stmt	= null;
		$stmtId	= __CLASS__."::".__FUNCTION__;
		if($this->_db->has($stmtId)) {
			$stmt = $this->_db->get($stmtId);
		} else {
			$prefix	= $this->_PropertiesPrefix;
			$table	= $this->_dbprefix.$this->_PropertiesTable;
				
			$query = "update {$this->_dbprefix}{$table}\n";
			$query.= "set    {$prefix}id = :newid\n";
			$query.= "where  {$prefix}id = :currentid\n";

			$stmt = $this->_db->prepare($stmtId, $query);
		}

		$params = array(
				":newid"	=> $id,
				":currentid"	=> $this->id
		);

		$stmt->execute($params);

		$this->load($id);

		return $this->ok();
	}

	//
	// Protected methods
}
?>